//1.哈希表
class Solution {
public:
    int longestConsecutive(vector<int>& nums) {
        unordered_set<int> hashset(nums.begin(), nums.end());
        int maxLen = 0;

        for (auto& e : hashset) {
            // 只从起点开始向右扩展
            if (!hashset.count(e - 1)) {  //左边无数字,即当前数字是起点
                int curr = e;
                int compare = 1;
                while (hashset.count(curr + 1)) { //存在子序列
                    curr++;
                    compare++;
                }
                maxLen = max(maxLen, compare);
            }
        }
        return maxLen;
    }
};
